import { http } from "@/utils/http";
import type { R } from "@/types/api";

/**
 * 上传图片/文件
 * @param file 要上传的文件
 * @returns R<string> 服务器返回的文件路径
 */
export function uploadFile(file: File) {
  const formData = new FormData();
  formData.append("file", file);
  return http.post<R<string>>("/upload", formData, {
    baseURL: import.meta.env.VITE_COMMON_API_URL, // 覆盖 baseURL
    headers: {
      "Content-Type": "multipart/form-data",
    },
  });
}

/**
 * 获取图形验证码
 * @returns R<{captchaId: string, captchaImage: string}> 验证码信息
 */
export function getCaptcha() {
  return http.get<R<{ captchaId: string; captchaImage: string }>>(
    "/captcha",
    {
      baseURL: import.meta.env.VITE_COMMON_API_URL,
    }
  );
}
